﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using StockMatch.WebSite.Mvc;

namespace StockMatch.WebSite
{
    public class AdminControllerBase:Controller
    {
        protected CurrentAdminUser CurrentAdminUser { get; set; }
        protected override void OnActionExecuting(ActionExecutingContext context)
        {
            base.OnActionExecuting(context);
            CurrentAdminUser = Request.GetCookieValue<CurrentAdminUser>(WebConfig.AdminCookieName);
            if (CurrentAdminUser == null)
            {
                //设置登录成功后转向的URL，格式例如:http://xxx.xxx/login.aspx?ReturnUrl=www.baidu.cn
                string returnUrl = string.Format("?ReturnUrl={0}",Server.UrlEncode(Request.Url.AbsoluteUri));
                //重定向到登录的URL后面的returnUrl参数用于登录通过后的页面跳转
                string loginUrl = Url.DomainRouteUrl(AreasConfig.AdminSite,"Index", "AdminHome") + returnUrl;
                Response.Redirect(loginUrl);
            }
        }
    }
}
